import streamlit as st
from page.page import Page
from st_aggrid import AgGrid, GridOptionsBuilder, GridUpdateMode, ColumnsAutoSizeMode, JsCode
import pandas as pd
from streamlit_extras.grid import grid
import requests
import json


class DataMiningMLLMDetail(Page):
    def write(self):
        task_name = st.query_params['task_name']

        df = pd.read_csv('/Users/cainsun/Downloads/wukong_test/data.csv')

        prefix = f"http://9.134.12.32:8501/app/static/data/public_data/wukong_test/"
        df['image'] = df['image_name'].apply(lambda x: prefix + x)
        # df = df.drop('Unnamed: 0', axis=1)

        def hold_page():
            st.query_params['page'] = 'data_mining_mllm_detail'
            st.query_params['task_name'] = task_name

        def onchange():
            hold_page()

        selected_df = None
        if 'mllm_types' in st.session_state:
            mllm_types = st.session_state['mllm_types']
            if 'all' in mllm_types:
                selected_df = df
            else:
                selected_df = df[df['type'].isin(mllm_types)]
        else:
            selected_df = df

        st.multiselect('请选择场景类型',key='mllm_types',on_change=onchange, options=['all', '数据图理解', '单/多表格理解', '混合图像理解', '文字信息提取', '测量读数', '指针型读数','地图解析','文档阅读理解','广告理解','聊天截图问答','手写/印刷区分','行业知识储备','语种理解','证件','内容描述'], default=['all'])
        st.data_editor(selected_df, use_container_width=True,
                        column_config={
                            'image': st.column_config.ImageColumn(),
                        },
                       column_order=['image', 'question', 'answer', 'type', 'reason']
                      )


        # st.markdown(" $x_{11} & x_{12} & \cdots & x_{1p}$ ")




data_mining_mllm_detail = DataMiningMLLMDetail('data_mining_mllm_detail')
